<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Schema;

class ShareReportSetting extends Model
{
    protected $fillable = [
        'share_reports_enabled',
        'branding_text',
        'report_logo_path',
        'watermark',
        'brand_color',
        'allow_profit_display',
        'show_badges',
        'show_motivational_line',
        'motivational_line',
        'default_template',
    ];

    protected function casts(): array
    {
        return [
            'share_reports_enabled' => 'boolean',
            'allow_profit_display' => 'boolean',
            'show_badges' => 'boolean',
            'show_motivational_line' => 'boolean',
        ];
    }

    public static function current(): self
    {
        if (! Schema::hasTable('share_report_settings')) {
            return new self(self::defaults());
        }

        return self::query()->firstOrCreate([], [
            ...self::defaults(),
        ]);
    }

    public static function defaults(): array
    {
        return [
            'share_reports_enabled' => true,
            'branding_text' => 'ViZuTrade Trading Report',
            'report_logo_path' => null,
            'watermark' => 'Generated by ViZuTrade',
            'brand_color' => '#2563EB',
            'allow_profit_display' => true,
            'show_badges' => true,
            'show_motivational_line' => true,
            'motivational_line' => 'Discipline builds confidence. Keep reviewing, keep improving.',
            'default_template' => 'premium-blue',
        ];
    }
}
