package models

import "odoo-go/pkg/orm"

// initHrExpense registers the hr.expense and hr.expense.sheet models.
// Mirrors: odoo/addons/hr_expense/models/hr_expense.py
func initHrExpense() {
	orm.NewModel("hr.expense", orm.ModelOpts{
		Description: "Expense",
		Order:       "date desc, id desc",
	}).AddFields(
		orm.Char("name", orm.FieldOpts{String: "Description", Required: true}),
		orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
		orm.Many2one("product_id", "product.product", orm.FieldOpts{String: "Expense Type"}),
		orm.Date("date", orm.FieldOpts{String: "Date", Required: true}),
		orm.Monetary("total_amount", orm.FieldOpts{String: "Total", Required: true, CurrencyField: "currency_id"}),
		orm.Monetary("unit_amount", orm.FieldOpts{String: "Unit Price", CurrencyField: "currency_id"}),
		orm.Float("quantity", orm.FieldOpts{String: "Quantity", Default: 1}),
		orm.Many2one("currency_id", "res.currency", orm.FieldOpts{String: "Currency"}),
		orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
		orm.Many2one("sheet_id", "hr.expense.sheet", orm.FieldOpts{String: "Expense Report"}),
		orm.Many2one("account_id", "account.account", orm.FieldOpts{String: "Account"}),
		orm.Selection("state", []orm.SelectionItem{
			{Value: "draft", Label: "To Submit"},
			{Value: "reported", Label: "Submitted"},
			{Value: "approved", Label: "Approved"},
			{Value: "done", Label: "Paid"},
			{Value: "refused", Label: "Refused"},
		}, orm.FieldOpts{String: "Status", Default: "draft"}),
		orm.Selection("payment_mode", []orm.SelectionItem{
			{Value: "own_account", Label: "Employee (to reimburse)"},
			{Value: "company_account", Label: "Company"},
		}, orm.FieldOpts{String: "Payment By", Default: "own_account"}),
		orm.Text("description", orm.FieldOpts{String: "Notes"}),
		orm.Binary("receipt", orm.FieldOpts{String: "Receipt"}),
	)

	orm.NewModel("hr.expense.sheet", orm.ModelOpts{
		Description: "Expense Report",
		Order:       "create_date desc",
	}).AddFields(
		orm.Char("name", orm.FieldOpts{String: "Report Name", Required: true}),
		orm.Many2one("employee_id", "hr.employee", orm.FieldOpts{String: "Employee", Required: true}),
		orm.Many2one("manager_id", "hr.employee", orm.FieldOpts{String: "Manager"}),
		orm.One2many("expense_line_ids", "hr.expense", "sheet_id", orm.FieldOpts{String: "Expenses"}),
		orm.Monetary("total_amount", orm.FieldOpts{String: "Total", Compute: "_compute_total", Store: true, CurrencyField: "currency_id"}),
		orm.Many2one("currency_id", "res.currency", orm.FieldOpts{String: "Currency"}),
		orm.Many2one("company_id", "res.company", orm.FieldOpts{String: "Company"}),
		orm.Selection("state", []orm.SelectionItem{
			{Value: "draft", Label: "Draft"},
			{Value: "submit", Label: "Submitted"},
			{Value: "approve", Label: "Approved"},
			{Value: "post", Label: "Posted"},
			{Value: "done", Label: "Paid"},
			{Value: "cancel", Label: "Refused"},
		}, orm.FieldOpts{String: "Status", Default: "draft"}),
		orm.Many2one("account_move_id", "account.move", orm.FieldOpts{String: "Journal Entry"}),
	)
}
