<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * @property int $id
 * @property int $client_id
 * @property string|null $card_number
 * @property string $holder_name
 * @property string $expiration
 * @property string|null $cvv
 * @property string|null $card_name
 * @property string|null $brand
 * @property string $last_four_digits
 * @property bool $is_active
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property string|null $token
 * @property string|null $gateway_card_id
 * @property string|null $idempotency_key
 * @property-read \App\Models\Client $client
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod query()
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereBrand($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereCardName($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereCardNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereClientId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereCvv($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereExpiration($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereGatewayCardId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereHolderName($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereIdempotencyKey($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereIsActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereLastFourDigits($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereToken($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod withTrashed(bool $withTrashed = true)
 * @method static \Illuminate\Database\Eloquent\Builder<static>|ClientPaymentMethod withoutTrashed()
 * @mixin \Eloquent
 */
class ClientPaymentMethod extends Model
{
    use HasFactory, SoftDeletes;

    protected $fillable = [
        'client_id',
        'token',
        'gateway_card_id',
        'idempotency_key',
        'card_number',
        'holder_name',
        'expiration',
        'cvv',
        'card_name',
        'brand',
        'last_four_digits',
        'is_active',
    ];

    protected $casts = [
        'token'       => 'encrypted',
        'card_number' => 'encrypted',
        'cvv'         => 'encrypted',
        'is_active'   => 'boolean',
        'created_at'  => 'datetime',
        'updated_at'  => 'datetime',
        'deleted_at'  => 'datetime',
    ];

    protected $hidden = [
        'token',
        'gateway_card_id',
        'card_number',
        'cvv',
    ];

    public function client(): BelongsTo
    {
        return $this->belongsTo(Client::class);
    }
}
