<?php

namespace Kylin\Ecommerce\Models;

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

/**
 * 商家模型
 *
 * 依据《电子商务法》第十条和第二十七条，
 * 商家需提交真实身份信息并通过认证。
 */
class Merchant extends Model
{
    use SoftDeletes;

    protected $table = 'ecommerce_merchants';

    protected $fillable = [
        'user_id', 'shop_name', 'shop_logo', 'type',
        'company_name', 'credit_code', 'legal_person_name', 'legal_person_id_card',
        'business_license', 'contact_name', 'contact_phone',
        'verification_status', 'verification_remark', 'verified_at', 'status',
    ];

    protected $casts = [
        'verified_at' => 'datetime',
    ];

    public function user(): BelongsTo
    {
        return $this->belongsTo(\App\Models\User::class);
    }

    public function products(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(Product::class, 'merchant_id');
    }

    public function orders(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(Order::class, 'merchant_id');
    }
}