<?php

declare(strict_types=1);

namespace App\Model;

use OpenApi\Attributes as OA;

/**
 * @property int $id 主键
 * @property int $company_id 公司 ID
 * @property int $platform_id 平台 ID
 * @property int $store_id 店铺 ID
 * @property int $status_id 产品状态 ID
 * @property int $type_id 产品类型 ID
 * @property int|null $warehouse_id 仓库 ID
 * @property int|null $sub_warehouse_id 子仓库 ID
 * @property string $platform_item_id 平台商品 ID
 * @property string|null $platform_model_id 平台规格 ID
 * @property string|null $origin_sku_id 品牌方原始 SKU ID
 * @property string|null $mapped_sku_id 映射后的 SKU ID
 * @property string|null $barcode 条形码
 * @property string|null $hscode 海关货物编码
 * @property array|null $bundled 组合商品信息
 * @property string $price 售价
 * @property string $currency 货币代码
 * @property int $num 可售卖数量
 * @property string|null $url 平台 URL
 * @property string|null $picture 图片链接
 * @property string $hash raw 字段的 MD5 哈希值
 * @property string|null $name 商品名称
 * @property array $raw 平台返回的原始产品信息
 * @property array|null $ext 扩展字段
 * @property \Carbon\Carbon|null $created_date 商品在平台的创建时间
 * @property \Carbon\Carbon|null $updated_date 商品在平台的更新时间
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 */
#[OA\Schema(
    schema: 'Product',
    type: 'object',
    properties: [
        new OA\Property(property: 'id', type: 'integer', example: 1),
        new OA\Property(property: 'company_id', type: 'integer', example: 1),
        new OA\Property(property: 'platform_id', type: 'integer', example: 2),
        new OA\Property(property: 'store_id', type: 'integer', example: 100),
        new OA\Property(property: 'status_id', type: 'integer', example: 1),
        new OA\Property(property: 'type_id', type: 'integer', example: 1),
        new OA\Property(property: 'platform_item_id', type: 'string', example: 'ITEM-001'),
        new OA\Property(property: 'platform_model_id', type: 'string', nullable: true, example: 'MODEL-A'),
        new OA\Property(property: 'name', type: 'string', nullable: true, example: 'iPhone 16 Pro'),
        new OA\Property(property: 'price', type: 'number', format: 'decimal', example: 99.99),
        new OA\Property(property: 'currency', type: 'string', example: 'CNY'),
        new OA\Property(property: 'num', type: 'integer', example: 100),
        new OA\Property(property: 'hash', type: 'string', example: 'a1b2c3d4e5f6...'),
        new OA\Property(property: 'raw', type: 'object', nullable: true, description: '平台原始数据'),
        new OA\Property(property: 'ext', type: 'object', nullable: true, description: '扩展字段'),
        new OA\Property(property: 'created_date', type: 'string', format: 'date-time', nullable: true),
        new OA\Property(property: 'updated_date', type: 'string', format: 'date-time', nullable: true),
        new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
        new OA\Property(property: 'updated_at', type: 'string', format: 'date-time'),
    ]
)]
class Product extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'products';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [
        'id',
        'company_id',
        'platform_id',
        'store_id',
        'status_id',
        'type_id',
        'warehouse_id',
        'sub_warehouse_id',
        'platform_item_id',
        'platform_model_id',
        'origin_sku_id',
        'mapped_sku_id',
        'barcode',
        'hscode',
        'bundled',
        'price',
        'currency',
        'num',
        'url',
        'picture',
        'hash',
        'name',
        'raw',
        'ext',
        'created_date',
        'updated_date',
        'created_at',
        'updated_at',
    ];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = [
        'id' => 'integer',
        'company_id' => 'integer',
        'platform_id' => 'integer',
        'store_id' => 'integer',
        'status_id' => 'integer',
        'type_id' => 'integer',
        'warehouse_id' => 'integer',
        'sub_warehouse_id' => 'integer',
        'price' => 'decimal:2',
        'num' => 'integer',
        'bundled' => 'json',
        'raw' => 'json',
        'ext' => 'json',
        'created_date' => 'datetime',
        'updated_date' => 'datetime',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];
}
