<?php

namespace App\Models;

use App\Entities\UserSNSEntity;

class UserSNSModel extends CommonModel
{
    const TABLE = "user_sns";
    const PK = "uid";
    const TITLE = "name";
    const PARENT = "user_uid";
    const SITE = "site";
    protected $table = self::TABLE;
    protected $primaryKey = self::PK;
    protected $returnType = UserSNSEntity::class;
    protected $allowedFields = [
        "uid",
        "site",
        "user_uid",
        "id",
        "name",
        "email",
        "detail",
        "status",
        "updated_at"
    ];
    public function __construct()
    {
        parent::__construct();
    }
    public function getFormRule(string $action, string $field): string
    {
        switch ($field) {
            case "id":
                $rule = "required|trim|min_length[4]|is_unique[{$this->table}.{$field}]";
                break;
            case $this->getTitleField():
                $rule = "required|trim|string";
                break;
            case "site":
                $rule = "required|trim|string";
                break;
            case "email":
                $rule = "required|trim|valid_email";
                break;
            case "detail":
                $rule = "required|trim|string";
                break;
            default:
                $rule = parent::getFormRule($action, $field);
                break;
        }
        return $rule;
    }
}
