<?php

namespace Vendtics\App\Repositories;

defined( "ABSPATH" ) || exit;

class SettingsRepository {
    private const OPTION_KEY = 'vendtics_settings';

    protected $default_settings = [
        'business'     => [
            'company'          => "Vendtics",
            'phone'            => '',
            'address_line_one' => '',
            'address_line_two' => '',
            'country'          => '',
            'state'            => '',
            'city'             => '',
            'zip_code'         => ''
        ],
        'general'      => [
            'unsubscribe_confirm_page'  => '',
            'after_unsubscribe'         => 'redirect_to_page', // redirect_to_page | redirect_to_custom_url
            'unsubscribe_redirect_page' => '',
            'unsubscribe_redirect_url'  => '',
        ],
        'email'        => [
            'from_name'      => '',
            'from_email'     => '',
            'frequency_type' => 'recommended', // recommended | manual
            'limit'          => 300,
            'frequency'      => '60_min'
        ],
        'double_optin' => [
            'status'             => false,
            'email_subject'      => '',
            'email_pre_header'   => '',
            'email_body'         => '',
            'after_confirmation' => 'redirect_to_page',  // redirect_to_page | redirect_to_custom_url
            'redirect_to_page'   => '',
            'redirect_url'       => '',
        ]
    ];

    public function get_settings() {
        return vendtics_array_merge_deep( $this->default_settings, get_option( self::OPTION_KEY, [] ) );
    }

    public function save_settings( array $settings ) {
        return update_option( self::OPTION_KEY, $settings );
    }
}