package models

import "odoo-go/pkg/orm"

// initAccountPaymentMethod registers account.payment.method and account.payment.method.line.
// Mirrors: odoo/addons/account/models/account_payment_method.py
//
// account.payment.method defines how payments are processed (e.g. manual, check, electronic).
// account.payment.method.line links a payment method to a journal with a specific sequence.
func initAccountPaymentMethod() {
	m := orm.NewModel("account.payment.method", orm.ModelOpts{
		Description: "Payment Method",
	})

	m.AddFields(
		orm.Char("name", orm.FieldOpts{String: "Name", Required: true, Translate: true}),
		orm.Char("code", orm.FieldOpts{String: "Code", Required: true}),
		orm.Selection("payment_type", []orm.SelectionItem{
			{Value: "inbound", Label: "Inbound"},
			{Value: "outbound", Label: "Outbound"},
		}, orm.FieldOpts{String: "Payment Type", Required: true}),
	)

	// -- Payment Method Line --
	// Links a payment method to a journal, controlling which methods are available per journal.
	// Mirrors: odoo/addons/account/models/account_payment_method.py AccountPaymentMethodLine
	pml := orm.NewModel("account.payment.method.line", orm.ModelOpts{
		Description: "Payment Method Line",
		Order:       "sequence, id",
	})

	pml.AddFields(
		orm.Many2one("payment_method_id", "account.payment.method", orm.FieldOpts{
			String: "Payment Method", Required: true, OnDelete: orm.OnDeleteCascade,
		}),
		orm.Many2one("journal_id", "account.journal", orm.FieldOpts{
			String: "Journal", Required: true, OnDelete: orm.OnDeleteCascade,
		}),
		orm.Integer("sequence", orm.FieldOpts{String: "Sequence", Default: 10}),
		orm.Char("name", orm.FieldOpts{
			String: "Name", Related: "payment_method_id.name",
		}),
		orm.Char("code", orm.FieldOpts{
			String: "Code", Related: "payment_method_id.code",
		}),
		orm.Selection("payment_type", []orm.SelectionItem{
			{Value: "inbound", Label: "Inbound"},
			{Value: "outbound", Label: "Outbound"},
		}, orm.FieldOpts{String: "Payment Type", Related: "payment_method_id.payment_type"}),
		orm.Many2one("payment_account_id", "account.account", orm.FieldOpts{
			String: "Outstanding Receipts/Payments Account",
			Help:   "Account used for outstanding payments/receipts with this method",
		}),
		orm.Many2one("company_id", "res.company", orm.FieldOpts{
			String: "Company", Related: "journal_id.company_id",
		}),
	)
}
