<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Report extends Model
{
    //
    const NOT_PROCESSED = 0;
    const PROCESSED = 1;

    const DUPLICATE = 1;
    const WRONG_REALITY = 2;
    const WRONG_INFO = 3;
    const SPAM_SCAM = 4;
    const OTHER = 5;
    const AGENCY = 6;


    const HOSTEL = 0;
    const ROOM_NEED_MORE = 1;
    const POST_NEWS =2;


    public function getReportTypeTextAttribute()
    {
        $type = $this->attributes['report_type'];

        $message = '';

        switch ($type) {
            case self::DUPLICATE:
                $message = 'Tin bị trùng lặp';
                break;
            case self::WRONG_REALITY:
                $message = 'Nội dung không đúng thực tế';
                break;
            case self::WRONG_INFO:
                $message = 'Thông tin bị sai lệch';
                break;
            case self::SPAM_SCAM:
                $message = 'Spam / Scam';
                break;
            case self::AGENCY:
                $message = 'Tin môi giới';
                break;
            case self::OTHER:
                $message = 'Khác';
                break;
            default:
                break;
        }

        return $message;
    }

    public function getObjectTextAttribute()
    {
        $objectId = $this->attributes['object_id'];
        $objectType = $this->attributes['object_type'];

        if ($objectType == self::HOSTEL) {
            $object = Hostel::find($objectId);
            if($object) {

                return '<a href="' . url('nha-tro/' . str_slug($object->name) . '-' . $object->id) . '">' . $object->name . '</a>';
            }
        } else if ($objectType == self::ROOM_NEED_MORE) {
            $object = RoomNeedMore::find($objectId);

            if($object) {
                return '<a href="' . url('phong-ghep/' . str_slug($object->name) . '-' . $object->id) . '">' . $object->name . '</a>';
            }
        }

        return '';
    }

    protected $fillable = [
        'report_type',
        'message',
        'object_type',
        'status',
        'user_id',
        'created_at',
        'updated_at',
        'deleted_at',
        'object_id'
    ];

    protected $dates = [
        'created_at',
        'updated_at',
        'deleted_at'
    ];
}
