from rest_framework import serializers

from .models import CreditAccount, CreditLedger, CreditReservation, QuotaPolicy


class CreditAccountSerializer(serializers.ModelSerializer):
    class Meta:
        model = CreditAccount
        fields = ["id", "balance", "reserved_balance", "currency", "updated_at"]
        read_only_fields = fields


class CreditLedgerSerializer(serializers.ModelSerializer):
    class Meta:
        model = CreditLedger
        fields = [
            "id",
            "user",
            "project",
            "task",
            "ledger_type",
            "amount",
            "balance_after",
            "reason",
            "metadata",
            "created_at",
        ]
        read_only_fields = fields


class CreditReservationSerializer(serializers.ModelSerializer):
    class Meta:
        model = CreditReservation
        fields = ["id", "user", "project", "task", "amount", "status", "expires_at", "created_at"]
        read_only_fields = fields


class QuotaPolicySerializer(serializers.ModelSerializer):
    class Meta:
        model = QuotaPolicy
        fields = ["id", "user", "project", "monthly_limit", "project_limit", "per_task_limit", "is_active"]
        read_only_fields = ["id"]

