<?php

namespace App\Forms;

use App\Forms\CommonForm;

class PaymentForm extends CommonForm
{
  public function __construct()
  {
    parent::__construct();
  }
  public function getFormRule(string $action, string $field): string
  {
    switch ($field) {
      case "user_uid":
      case "clientinfo_uid":
      case "serviceinfo_uid":
      case "amount":
        $rule = "required|numeric";
        break;
      case "serverpartinfo_uid":
        $rule = "permit_empty|numeric";
        break;
      case "title":
      case "billing":
      case "pay":
      case "status":
        $rule = "required|trim|string";
        break;
      case "billing_at":
        $rule = "required|valid_date";
        break;
      case "content":
        $rule = "permit_empty|trim|string";
        break;
      default:
        $rule = parent::getFormRule($action, $field);
        break;
    }
    return $rule;
  }

  public function getFormOption(string $action, string $field, array $formDatas = [], array $options = ['options' => [], 'atttributes' => []]): array
  {
    $tempOptions = ['' => lang("{$this->getAttribute('class_path')}.label.{$field}") . " 선택"];
    switch ($field) {
      case 'serviceinfo_uid':
        foreach ($this->getFormOption_process(service('customer_serviceservice'), $action, $field, $formDatas) as $tempEntity) {
          $tempOptions[$tempEntity->getPK()] = $tempEntity->getTitle();
          // $options['attributes'][$tempEntity->getPK()] = ['data-role' => implode(DEFAULTS['DELIMITER_ROLE'], $tempEntity->getRole())];
        }
        $options['options'] = $tempOptions;
        break;
      default:
        $options = parent::getFormOption($action, $field, $formDatas, $options);
        break;
    }
    return $options;
  }
}
