<?php

namespace App\Mail;

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

class InvalidQualityMail extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     */
    public $serial;
    public $invoiceNumber;
    public $mplantName;
    public $mProdOrder;

    public $mUserName;

    public $mPartNo;
    public $mailType;
    public $greeting;
    public $subjectLine;

    public $mExpectedValue;

    public $mLinePart;

    public $itemCode;
    public function __construct($parNo, $mProdOrder, $mplantName, $mLinePart, $mUserName, $mExpectedValue, $mailType = 'InvalidPartNumber')
    {
        $this->mPartNo = $parNo;
        $this->mProdOrder = $mProdOrder;
        $this->mplantName = $mplantName;
        $this->mLinePart = $mLinePart;
        $this->mUserName = $mUserName;
        $this->mailType = $mailType;
        $this->mExpectedValue = $mExpectedValue;
    }

    public function envelope(): Envelope
    {
        // dynamic subject based on mail type
        switch ($this->mailType) {
            case 'InvalidPartNumber2':
                $this->subjectLine = "Quality Part Validation ({$this->mplantName})";
                break;
            case 'InvalidPartNumber3':
                $this->subjectLine = "Quality Part Validation ({$this->mplantName})";
                break;
            case 'InvalidPartNumber4':
                $this->subjectLine = "Quality Part Validation ({$this->mplantName})";
                break;
            case 'InvalidPartNumber5':
                $this->subjectLine = "Quality Part Validation ({$this->mplantName})";
                break;
            case 'FinalInspectionNotOk':
                $this->subjectLine = "Quality Part Validation Inspection Status ({$this->mplantName})";
                break;
            case 'InvalidTubeStickerPump':
                $this->subjectLine = "Quality Part Validation ({$this->mplantName})";
                break;
            case 'InvalidPartNumber':
            default:
                $this->subjectLine = "Quality Part Validation ({$this->mplantName})";
                break;
        }

        return new Envelope(
            subject: $this->subjectLine,
        );
    }

    public function content(): Content
    {
        // dynamic greeting/message body
        switch ($this->mailType) {
            case 'InvalidPartNumber2':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned part number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Part Number 2:</b> {$this->mPartNo}<br>
                    <b>Expected Scanned Part Number 2:</b> {$this->mExpectedValue}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidPartNumber3':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned part number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Part Number 3:</b> {$this->mPartNo}<br>
                    <b>Expected Scanned Part Number 2:</b> {$this->mExpectedValue}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidPartNumber4':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned part number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Part Number 4:</b> {$this->mPartNo}<br>
                    <b>Expected Scanned Part Number 2:</b> {$this->mExpectedValue}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidPartNumber5':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned part number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Part Number 5:</b> {$this->mPartNo}<br>
                    <b>Expected Scanned Part Number 2:</b> {$this->mExpectedValue}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'FinalInspectionNotOk':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the final inspection is not ok for scanned serial number.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Serial Number:</b> {$this->mPartNo}<br>
                    <b>Final Inspection :</b>Not OK<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidTubeStickerPump':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned tube sticker pump serial number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Tube Pump QR:</b> {$this->mPartNo}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidTubeStickerMotor':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned tube sticker motor serial number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Tube Motor QR:</b> {$this->mPartNo}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidTubeStickerPumpset':
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned tube sticker pumpset serial number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Tube Pumpset QR:</b> {$this->mPartNo}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
            case 'InvalidPartNumber':
            default:
                $this->greeting = "
                    Dear Sir/Madam,<br><br>
                    Please note that the scanned part number appears to be incorrect.<br>
                    <b>Plant:</b> {$this->mplantName}<br>
                    <b>Line Name:</b> {$this->mLinePart}<br>
                    <b>Production Order:</b> {$this->mProdOrder}<br>
                    <b>Scanned Part Number 1:</b> {$this->mPartNo}<br>
                    <b>Expected Scanned Part Number 1:</b> {$this->mExpectedValue}<br>
                    <b>Employee Code:</b> {$this->mUserName}<br>
                ";
                break;
        }

        return new Content(
            view: 'mail.invalid-serial',
            with: [
                'company' => "CRI Digital Manufacturing Solutions",
                'greeting' => $this->greeting,
                'wishes' => "Thanks & Regards,<br>CRI Digital Manufacturing Solutions",
            ],
        );
    }

    /**
     * Get the attachments for the message.
     *
     * @return array<int, \Illuminate\Mail\Mailables\Attachment>
     */
    public function attachments(): array
    {
        return [];
    }
}
