<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\History;
use App\Supports\Response;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

/**
 * @group Lottery Prize
 */
class HistoryController extends Controller
{
    public function __construct(
    )
    {
    }

    public function list($locate = 'tw')
    {
        $locate = $locate == "tw" ? "zh_TW" : $locate;
        $data = History::where("visible", 1)->orderByDesc("selected_year", "desc")->orderByDesc("selected_month")->get();
        $yearList = History::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
        $result = [];
        $result["yearList"] = $yearList;
        foreach($data as $item){
            $result["list"][$item->selected_year][] = [
                "operateMonth " => $item->selected_year . "." . $item->selected_month,
                "title" => $item->getTranslation("title", $locate),
                "imgUrl" => $item->img_url_link
            ];
        }
        return Response::ok($result);
    }
}
