<?php

namespace Database\Seeders;

use App\Photo;
use Illuminate\Database\Seeder;

class ExportFirstPackage extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        /*$originPath = public_path('uploads/files/aws/');
        $resultPath = public_path('uploads/colors/package1/');
        $logFile = $resultPath . "Export.csv";

        $photos = Photo::where('rs_status', 3)
            ->whereNotNull('file_color')
            ->limit(3750)
            ->orderBy('id')
            ->get();

        $log = '"No.", "ID", "Origin", "Color", "Mix"' . "\r\n";
        foreach ($photos as $key => $photo) {
            if (file_exists($originPath . $photo->file_color)) {
                copy($originPath . $photo->file_url, $resultPath . $photo->file_url);
                copy($originPath . $photo->file_color, $resultPath . $photo->file_color);
            }
            if (file_exists($originPath . $photo->file_mix)) {
                copy($originPath . $photo->file_mix, $resultPath . $photo->file_mix);
            }

            $log .= '"' . ($key + 1) . '", "' . $photo->id . '", "' . $photo->file_url . '", "' . $photo->file_color . '", "' . $photo->file_mix . '"' . "\r\n";
            print  "[" . ($key + 1) . "] " . $photo->file_url . "\r\n";
        }

        file_put_contents($logFile, "");
        file_put_contents($logFile, $log);*/


        //Fix
        $originPath = public_path('uploads/files/aws/');
        $resultPath = public_path('uploads/colors/package1_fix/');
        $logFile = $resultPath . "Export.csv";
        $listIds = [21, 66, 70, 72, 74, 77, 102, 103, 104, 106, 146, 149, 205, 227, 305, 307, 2048, 2096, 2099, 3193, 3196, 3524, 3843, 3844, 4402, 4405, 4451, 4454, 4455, 4457];

        $photos = Photo::where('rs_status', 3)
            ->whereNotNull('file_color')
            ->whereIn('id', $listIds)
            ->orderBy('id')
            ->get();

        $log = '"No.", "ID", "Origin", "Color", "Mix"' . "\r\n";
        foreach ($photos as $key => $photo) {
            if (file_exists($originPath . $photo->file_color)) {
                copy($originPath . $photo->file_url, $resultPath . $photo->file_url);
                copy($originPath . $photo->file_color, $resultPath . $photo->file_color);
            }
            if (file_exists($originPath . $photo->file_mix)) {
                copy($originPath . $photo->file_mix, $resultPath . $photo->file_mix);
            }

            $log .= '"' . ($key + 1) . '", "' . $photo->id . '", "' . $photo->file_url . '", "' . $photo->file_color . '", "' . $photo->file_mix . '"' . "\r\n";
            print  "[" . ($key + 1) . "] " . $photo->file_url . "\r\n";
        }

        file_put_contents($logFile, "");
        file_put_contents($logFile, $log);
    }
}
