<?php

namespace App\Exports;

use App\Models\FbSubmission;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;

class FbSubmissionsExport implements FromCollection, WithHeadings
{
    protected $status;

    public function __construct($status)
    {
        $this->status = $status;
    }

    public function collection()
    {
        return FbSubmission::where('status', $this->status)
            ->with('user')
            ->get()
            ->map(function ($sub) {
                return [
                    'Name'           => $sub->user->name ?? 'N/A',
                    'Referral Code'  => $sub->user->referral_code ?? 'N/A',
                    'Facebook Link'  => $sub->fb_uid,
                    'Email'          => $sub->fb_email,
                    'Password'       => decrypt($sub->fb_password),
                    '2FA Key'        => decrypt($sub->fb_2fa),
                    'Cookie/Text'    => $sub->fb_cookie_link ?? '',
                ];
            });
    }

    public function headings(): array
    {
        return [
            'Name',
            'Referral Code',
            'Facebook Link',
            'Email',
            'Password',
            '2FA Key',
            'Cookie/Text',
        ];
    }
}
