<?php

namespace App\Controllers\Owner;

use App\Controllers\BaseController;
use App\Models\ProductCustomModel;

class ProductCustom extends BaseController
{
    protected $custom;

    public function __construct()
    {
        $this->custom = new ProductCustomModel();
    }

    public function index($id_product)
    {
        $data = [
            'title' => 'Harga Custom',
            'id_product' => $id_product,
            'customs' => $this->custom
                ->where('id_product', $id_product)
                ->findAll()
        ];

        return view('owner/product/custom', $data);
    }

    public function store()
    {
        $this->custom->insert([

            'id_product'       => $this->request->getPost('id_product'),

            'custom_name'      => $this->request->getPost('custom_name'),

            'additional_price' => $this->request->getPost('additional_price')

        ]);

        return redirect()->back()->with('success', 'Harga custom berhasil ditambahkan.');
    }

    public function delete($id)
    {
        $this->custom->delete($id);

        return redirect()->back()->with('success', 'Harga custom berhasil dihapus.');
    }
}