<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Payment method — cash / bank transfer / cheque / UPI / card etc.
 * Configured by the shop owner once, consumed by sales (POS checkout)
 * and supplier-payment flows.
 *
 * `requires_reference` drives a "Reference number" input that's
 * conditionally enforced (cheque #, UPI txn ID, card auth code).
 * `opens_cash_drawer` is a cashier-side concern — irrelevant here.
 *
 * This slice (supplier-payments) is the first consumer; the cashier
 * checkout slice will share the same model.
 */
class PaymentMethod extends Model
{
    protected $fillable = [
        'code', 'name', 'type', 'provider',
        'icon', 'color', 'provider_credentials',
        'requires_reference', 'opens_cash_drawer',
        'accounting_account_id', 'sort_order', 'is_active',
    ];

    protected function casts(): array
    {
        return [
            'provider_credentials' => 'array',
            'requires_reference'   => 'boolean',
            'opens_cash_drawer'    => 'boolean',
            'is_active'            => 'boolean',
            'sort_order'           => 'integer',
        ];
    }

    /** @param Builder<PaymentMethod> $q */
    public function scopeActive(Builder $q): void
    {
        $q->where('is_active', true);
    }
}
