<?php

namespace Modules\Payment\Models;

use App\Models\Model;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;
use Illuminate\Database\Eloquent\SoftDeletes;

class Wechat extends Model
{

    use Cachable,
        SoftDeletes;

    protected $table = 'payment_wechats';

    protected $casts = [
        'log' => 'json',
    ];

    /**
     * Notes   : 生成配置文件
     *
     * @Date   : 2021/5/26 2:21 下午
     * @Author : < Jason.C >
     * @return int[]
     */
    public function toConfig(): array
    {
        return [
            'app_id'               => $this->appid,//app
            'mp_app_id'            => $this->app_id,//mp
            'mini_app_id'          => $this->miniapp_id,//mini
            'mch_id'               => $this->mch_id,
            // 必填-商户秘钥
            'mch_secret_key'       => $this->key,
            // 必填-商户私钥 字符串或路径
            'mch_secret_cert'      => $this->cert_key ? storage_path('app/'.$this->cert_key) : '',
            // 必填-商户公钥证书路径
            'mch_public_cert_path' => $this->cert_client ? storage_path('app/'.$this->cert_client) : '',
            'logger'               => [
                'file'     => storage_path('logs/wechat/'.$this->log['file'].'.log'),
                'level'    => $this->log['level'],
                'type'     => $this->log['type'],
                'max_file' => (int) $this->log['max_file'],
            ],
        ];
    }

}
