package models

import "odoo-go/pkg/orm"

// initResCompany registers the res.company model.
// Mirrors: odoo/addons/base/models/res_company.py class Company
//
// In Odoo, companies are central to multi-company support.
// Every record can be scoped to a company via company_id.
func initResCompany() {
	m := orm.NewModel("res.company", orm.ModelOpts{
		Description: "Companies",
		Order:       "sequence, name",
		Inherits:    map[string]string{"res.partner": "partner_id"},
	})

	// -- Identity --
	m.AddFields(
		orm.Char("name", orm.FieldOpts{String: "Company Name", Required: true}),
		orm.Integer("sequence", orm.FieldOpts{String: "Sequence", Default: 10}),
		orm.Boolean("active", orm.FieldOpts{String: "Active", Default: true}),
		orm.Many2one("parent_id", "res.company", orm.FieldOpts{String: "Parent Company"}),
		orm.One2many("child_ids", "res.company", "parent_id", orm.FieldOpts{String: "Child Companies"}),
	)

	// -- Contact (delegates to partner) --
	// In Odoo: _inherits = {'res.partner': 'partner_id'}
	// We use explicit fields instead of delegation for clarity.
	m.AddFields(
		orm.Many2one("partner_id", "res.partner", orm.FieldOpts{
			String: "Partner", Required: true, OnDelete: orm.OnDeleteRestrict,
		}),
		orm.Char("street", orm.FieldOpts{String: "Street"}),
		orm.Char("street2", orm.FieldOpts{String: "Street2"}),
		orm.Char("zip", orm.FieldOpts{String: "Zip"}),
		orm.Char("city", orm.FieldOpts{String: "City"}),
		orm.Many2one("state_id", "res.country.state", orm.FieldOpts{String: "State"}),
		orm.Many2one("country_id", "res.country", orm.FieldOpts{String: "Country"}),
		orm.Char("email", orm.FieldOpts{String: "Email"}),
		orm.Char("phone", orm.FieldOpts{String: "Phone"}),
		orm.Char("mobile", orm.FieldOpts{String: "Mobile"}),
		orm.Char("website", orm.FieldOpts{String: "Website"}),
		orm.Char("vat", orm.FieldOpts{String: "Tax ID"}),
		orm.Char("company_registry", orm.FieldOpts{String: "Company ID (Registry)"}),
	)

	// -- Currency --
	m.AddFields(
		orm.Many2one("currency_id", "res.currency", orm.FieldOpts{
			String: "Currency", Required: true,
		}),
	)

	// -- Display --
	m.AddFields(
		orm.Binary("logo", orm.FieldOpts{String: "Company Logo"}),
		orm.Char("color", orm.FieldOpts{String: "Color"}),
		orm.Integer("font_color", orm.FieldOpts{String: "Font Color"}),
	)

	// -- Report Layout --
	m.AddFields(
		orm.Many2one("paperformat_id", "report.paperformat", orm.FieldOpts{String: "Paper Format"}),
		orm.HTML("report_header", orm.FieldOpts{String: "Company Tagline"}),
		orm.HTML("report_footer", orm.FieldOpts{String: "Report Footer"}),
	)

	// -- Fiscal --
	m.AddFields(
		orm.Many2one("account_fiscal_country_id", "res.country", orm.FieldOpts{String: "Fiscal Country"}),
	)
}
