<?php

namespace app\controllers\api\v1;

use app\common\ImageHelper;
use app\components\serializers\Serializer;
use app\controllers\BaseController;
use app\models\Brand;
use app\models\BrandRunway;
use app\models\BrandRunwayImages;
use yii\helpers\ArrayHelper;
use yii\web\Controller;

class RunwayController extends BaseController
{

    public function actionView()
    {

        $runwayId = \Yii::$app->request->get('id');

        $runway = BrandRunway::find()->where(['id' => $runwayId])->asArray()->one();
        $runway['brand_name'] = Brand::findOne($runway['brand_id'])->name;
        $runwayImages = BrandRunwayImages::find()->where(['runway_id' => $runway['id']])->asArray()->all();

        foreach ($runwayImages as &$image) {
            $image['s'] = ImageHelper::imageMogr2H480(\Yii::$app->params['cdnAddress'] . $image['name']);
            $image['xl'] = ImageHelper::imageMogr2H1080(\Yii::$app->params['cdnAddress'] . $image['name']);
        }

        return $this->asJson([
            'code' => 0,
            'data' => [
                'info' => $runway,
                'images' => $runwayImages
            ]
        ]);
    }
}