# -*- coding: utf-8 -*-
# Copyright 2026 Nexa Systems Inc.
# License OPL-1 (Odoo Proprietary License v1.0)

from odoo import models, fields


class FusionClockAIUsage(models.Model):
    _name = 'fusion.clock.ai.usage'
    _description = 'AI Usage Tracking'
    _order = 'date desc'

    date = fields.Date(required=True, index=True)
    feature = fields.Char(required=True, index=True)
    model_name = fields.Char(required=True)
    prompt_tokens = fields.Integer()
    completion_tokens = fields.Integer()
    total_tokens = fields.Integer(compute='_compute_total')
    estimated_cost_usd = fields.Float(digits=(10, 6))
    request_count = fields.Integer(default=1)
    company_id = fields.Many2one('res.company', default=lambda self: self.env.company)

    def _compute_total(self):
        for rec in self:
            rec.total_tokens = rec.prompt_tokens + rec.completion_tokens
