<?php

declare(strict_types=1);

namespace App\Model;



use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Collection;
use Hyperf\Database\Model\Relations\HasOne;
use Hyperf\Snowflake\Concern\Snowflake;

/**
 * @property int $bank_card_id 主键id
 * @property int $doctor_id 医生id
 * @property int $bank_id 银行id
 * @property string $bank_card_code 银行卡号
 * @property string $bank_card_code_mask 银行卡号（掩码）
 * @property string $account_name 开户人姓名
 * @property string $card_id_number 开户人身份证号
 * @property string $account_phone 开户人手机号
 * @property int $province_id 省份id
 * @property string $province 省份
 * @property int $city_id 城市id
 * @property string $city 城市
 * @property int $county_id 区县id
 * @property string $county 区县
 * @property \Carbon\Carbon $created_at 创建时间
 * @property \Carbon\Carbon $updated_at 修改时间
 */
class DoctorBankCard extends Model
{
    use Snowflake;

    /**
     * The table associated with the model.
     */
    protected ?string $table = 'doctor_bank_card';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['bank_card_id', 'doctor_id', 'bank_id', 'bank_card_code', 'bank_card_code_mask', 'account_name', 'card_id_number', 'account_phone', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'created_at', 'updated_at'];

    protected string $primaryKey = "bank_card_id";

    /**
     * 关联银行表
     */
    public function BasicBank(): HasOne
    {
        return $this->hasOne(BasicBank::class, 'bank_id','bank_id');
    }

    /**
     * 获取信息-单条
     * @param array $params
     * @param array $fields
     * @return object|null
     */
    public static function getOne(array $params, array $fields = ['*']): object|null
    {
        return self::where($params)->first($fields);
    }

    /**
     * 获取信息-多条
     * @param array $params
     * @param array $fields
     * @return object|null
     */
    public static function getList(array $params, array $fields = ['*']): object|null
    {
        return self::where($params)->get($fields);
    }


    /**
     * 获取医生银行卡-单条
     * 关联银行表
     * @param array $params
     * @param array $fields
     * @return object|null
     */
    public static function getWithBankOne(array $params, array $fields = ['*']): object|null
    {
        return self::with(['BasicBank'])->where($params)->first($fields);
    }

    /**
     * 新增
     * @param array $data
     * @return \Hyperf\Database\Model\Model|DoctorBankCard
     */
    public static function addDoctorBankCard(array $data): \Hyperf\Database\Model\Model|DoctorBankCard
    {
        return self::create($data);
    }

    /**
     * 修改
     * @param array $params
     * @param array $data
     * @return int
     */
    public static function editDoctorBankCard(array $params = [], array $data = []): int
    {
        return self::where($params)->update($data);
    }
}
