<?php

namespace App\Models\Service;

use App\Models\DomainRegistrar;
use App\Traits\ServiceDomains;

/**
 * Class Domain (Service)
 * Services that are managed Domain Names
 */
class Domain extends Type
{
	use ServiceDomains;

	protected $table = 'service_domain';
	protected $with = [
		'tld',
	];

	/* OVERRIDES */

	/**
	 * Service update validation
	 *
	 * @return array
	 */
	public function validation(): array
	{
		return [
			'domain_name' => 'nullable|string|min:2',
			'tld_id' => 'required|exists:tlds,id',
			'domain_registrar_id' => 'required|exists:domain_registrars,id',
			'registrar_account' => 'nullable|string',
			'registrar_ns' => 'nullable|string',
			'registrar_username' => 'nullable|string',
			'connect_at' => 'nullable|date',
			'start_at' => 'nullable|date',
			'expire_at' => 'nullable|date|after:start_at',
			'recur_schedule' => 'nullable|int',		// @todo insure value is at least 1 yr and not higher than Invoice::billing_periods
		];
	}

	/* RELATIONS */

	public function registrar()
	{
		return $this->belongsTo(DomainRegistrar::class,'domain_registrar_id');
	}
}