from __future__ import annotations

from decimal import Decimal

from app.models.four_pillars_schemas import (
    RentalContractReconciliation,
    ShiftLogVerificationStatus,
)


class RentalPillarMixin:
    """Trụ cột 3: Cho thuê Máy móc & Ca máy Cơ giới."""

    def reconcile_equipment_rental(
        self, equipment_code: str = "EXC-KOBELCO-02"
    ) -> RentalContractReconciliation:
        """Đối soát 3 bên ca máy cho thuê: Nhật ký ca máy vs Chấm công thợ vs Hóa đơn Cty Loan Khải (0201889988)."""
        logged_hours = Decimal("160.0000")
        timesheet_hours = Decimal("160.0000")
        invoiced_hours = Decimal("160.0000")
        rate = Decimal("650000.0000")
        earned_vnd = (invoiced_hours * rate).quantize(Decimal("0.0001"))

        # OEE = Tỷ lệ sẵn sàng (95%) * Hiệu suất (92%) * Chất lượng (100%) = 87.4%
        oee = Decimal("87.4000")

        return RentalContractReconciliation(
            partner_tax_id="0201889988",
            partner_name="Công ty TNHH Vận tải và Thương mại Loan Khải",
            equipment_code=equipment_code,
            equipment_name="Máy Đào Bánh Xích Kobelco SK200-8 (0.8m³)",
            total_shift_hours_logged=logged_hours,
            operator_timesheet_hours=timesheet_hours,
            invoiced_rental_hours=invoiced_hours,
            hourly_rate=rate,
            total_earned_vnd=earned_vnd,
            invoiced_amount_vnd=earned_vnd,
            hours_discrepancy=Decimal("0.0000"),
            oee_percentage=oee,
            status=ShiftLogVerificationStatus.MATCHED,
            notes="Máy hoạt động ổn định 20 ca (8h/ca). Chấm công thợ lái và biên bản xác nhận ca máy khớp 100%.",
        )
