<?php

declare(strict_types=1);

abstract class NotificationEmailActionBase implements MyronAction
{
    public function __construct(protected readonly NotificationEmailsService $service)
    {
    }
}

final class NotificationEmailsListAction extends NotificationEmailActionBase
{
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata('/api/v1/administration/notification-emails', 'GET', 'administration.notificationEmails', 'notification-email', 'list', ['type' => 'object', 'properties' => []], ['type' => 'object', 'properties' => ['notificationEmails' => ['type' => 'array']]], MyronApiScopes::ADMINISTRATION_READ, 'List verified destination addresses.', [], [], [], 3, [], false, null, true);
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        return MyronActionResult::ok($this->service->list(false));
    }
}

final class NotificationEmailsCreateAction extends NotificationEmailActionBase
{
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata('/api/v1/administration/notification-emails', 'POST', 'administration.notificationEmails', 'notification-email', 'create', ['type' => 'object', 'properties' => ['label' => ['type' => 'string'], 'address' => ['type' => 'string']], 'required' => ['label', 'address']], ['type' => 'object', 'properties' => ['notificationEmail' => ['type' => 'object']]], MyronApiScopes::ADMINISTRATION_WRITE, 'Create and send verification for a destination email.', ['inserts notification_emails row', 'sends verification email'], [], [], 4, ['notification-emails.create'], false, null, true);
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->create($input, $caller)); }
        catch (Throwable $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
    }
}

final class NotificationEmailsResendVerificationAction extends NotificationEmailActionBase
{
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata('/api/v1/administration/notification-emails/{neId}/resend-verification', 'POST', 'administration.notificationEmails', 'notification-email', 'resendVerification', ['type' => 'object', 'properties' => ['neId' => ['type' => 'string']], 'required' => ['neId']], ['type' => 'object', 'properties' => ['notificationEmail' => ['type' => 'object']]], MyronApiScopes::ADMINISTRATION_WRITE, 'Resend destination email verification.', ['rotates verification token', 'sends verification email'], [], [], 4, ['notification-emails.resend'], false, null, true);
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->resendVerification((string) $input['neId'])); }
        catch (Throwable $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
    }
}

final class NotificationEmailsDeleteAction extends NotificationEmailActionBase
{
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata('/api/v1/administration/notification-emails/{neId}', 'DELETE', 'administration.notificationEmails', 'notification-email', 'delete', ['type' => 'object', 'properties' => ['neId' => ['type' => 'string']], 'required' => ['neId']], ['type' => 'object', 'properties' => ['deleted' => ['type' => 'boolean']]], MyronApiScopes::ADMINISTRATION_WRITE, 'Delete a verified destination.', ['deletes notification_emails row'], [], [], 4, ['notification-emails.delete'], false, null, true);
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        return MyronActionResult::ok($this->service->delete((string) $input['neId']));
    }
}

final class NotificationEmailsSetDefaultAction extends NotificationEmailActionBase
{
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata('/api/v1/administration/notification-emails/{neId}/set-default', 'POST', 'administration.notificationEmails', 'notification-email', 'setDefault', ['type' => 'object', 'properties' => ['neId' => ['type' => 'string']], 'required' => ['neId']], ['type' => 'object', 'properties' => ['defaultNotificationEmailId' => ['type' => 'string']]], MyronApiScopes::ADMINISTRATION_WRITE, 'Set the default verified destination.', ['updates site_settings.default_notification_email_id'], [], [], 4, ['notification-emails.set-default'], false, null, true);
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        try { return MyronActionResult::ok($this->service->setDefault((string) $input['neId'])); }
        catch (Throwable $e) { return MyronActionResult::error('input_invalid', $e->getMessage()); }
    }
}

final class NotificationEmailsVerifyAction extends NotificationEmailActionBase
{
    public function metadata(): MyronActionMetadata
    {
        return new MyronActionMetadata('/verify-notification-email', 'GET', 'administration.notificationEmails', 'notification-email', 'verify', ['type' => 'object', 'properties' => ['ne_id' => ['type' => 'string'], 'token' => ['type' => 'string']], 'required' => ['ne_id', 'token']], ['type' => 'object', 'properties' => ['verified' => ['type' => 'boolean']]], null, 'Verify a destination email token.', ['updates notification_emails.verified_at'], [], [], 2, [], false, null, false);
    }

    public function execute(array $input, MyronActionCallerContext $caller): MyronActionResult
    {
        return MyronActionResult::ok(['verified' => $this->service->verify((string) $input['ne_id'], (string) $input['token'])]);
    }
}
