<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;

class WelcomeMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * @param  string       $userName        Full name of the new user
     * @param  string       $userEmail       Email address of the new user
     * @param  string       $orgName         Organisation name
     * @param  string       $role            Human-readable role label
     * @param  string       $loginUrl        URL to the login page
     * @param  string|null  $plainPassword   Plain-text password (only shown when admin creates a sub-user)
     * @param  bool         $isOrgOwner      True when this is a new org-owner registration
     * @param  string|null  $trialEndsAt     ISO8601 trial expiry (org-owner only)
     */
    public function __construct(
        public readonly string  $userName,
        public readonly string  $userEmail,
        public readonly string  $orgName,
        public readonly string  $role,
        public readonly string  $loginUrl,
        public readonly ?string $plainPassword = null,
        public readonly bool    $isOrgOwner    = false,
        public readonly ?string $trialEndsAt   = null,
    ) {}

    public function envelope(): Envelope
    {
        $subject = $this->isOrgOwner
            ? 'Welcome to ' . config('app.name') . ' — Your account is ready!'
            : 'Your ' . config('app.name') . ' account has been created';

        return new Envelope(subject: $subject);
    }

    public function content(): Content
    {
        return new Content(view: 'emails.welcome');
    }
}
