import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { roomDetail, SearchroomDetailModel } from '../models/roomDetail.model';

@Injectable({ providedIn: 'root' })
export class roomDetailService {

    constructor(private http: HttpClient) { }
    url: string;
    listroomDetail: roomDetail[] = [
        {
            Id: 1,
            room: {
                rId: 1,
                rName: "ห้องเดียว",
                rPic: "assets/img/room.jpg",
                roomLimit: 25,
                rDesc: "จำนวนคน 25 คน",
            },
            userName: 'เกม',
            sDate: '10/12/2560',
            eDate: '10/11/2561',
            sTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eStatus: 'รอการอนุมัติ',
            Remark: 'test',
        },
        {
            Id: 2,
            room: {
                rId: 2,
                rName: "ห้องคู่",
                rPic: "assets/img/room.jpg",
                roomLimit: 50,
                rDesc: "จำนวนคน 50 คน",
            },
            userName: 'เกม',
            sDate: '10/12/2560',
            eDate: '10/11/2561',
            sTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eTime: {
                hour: 22,
                minute: 30,
                second: 0
            },
            eStatus: 'รอการอนุมัติ',
            Remark: 'test',
        },

    ]

    addroomDetail(model: roomDetail) {
        console.log(this.listroomDetail);
        this.listroomDetail.push(model);

    }

    getListroomDetail() {
        return this.listroomDetail;
    }

    // getListroomDetail() {
    //   this.http.get(this.url).subscribe((response: any) => {
    //     console.log(response);
    //     this.listroomDetail = response.content;
    //   }, error => {
    //     console.log(error)
    //     // alert("ไม่สามารถดึงข้อมูลห้องประชุมได้ เนื่องจาก :\n" + error.message)
    //   })
    // }

    searchListroomDetail(searchModel: SearchroomDetailModel) {
        this.http.get(this.url + '&startDate=' + searchModel.sDate.split("-")[2] + '-' + searchModel.sDate.split("-")[1] + '-' + searchModel.sDate.split("-")[0] + '&endDate=' + searchModel.eDate.split("-")[2] + '-' + searchModel.eDate.split("-")[1] + '-' + searchModel.eDate.split("-")[0] + '&startTime=' + searchModel.sTime + ':00' + '&endTime=' + searchModel.eTime + ':00').subscribe((response: any) => {
            console.log(response);
            this.listroomDetail = response;
        }, error => {
            console.log(error)
            alert("ไม่สามารถค้นหาอุปกรณ์ที่ว่างได้ เนื่องจาก :\n" + error.message)
        })
    }

    // addEquirment(EquirmentModel: Equirment) {
    //   this.http.post(this.url, EquirmentModel).subscribe(response => {
    //     console.log(response);

    //   })


    // }
    deleteroomDetail(roomDetailModel: roomDetail) {
        this.http.delete(this.url + "/" + roomDetailModel.Id).subscribe(response => {
            console.log(response);
            this.getListroomDetail()
            alert("ลบข้อมูลอุปกรณ์สำเร็จ")
        })
    }

    updateroomDetail(roomDetailModel: roomDetail) {
        this.http.put(this.url + "/" + roomDetailModel.Id, roomDetailModel).subscribe(response => {
            console.log(response);
            alert("อัพเดทข้อมูลอุปกรณ์สำเร็จ")
        })
    }

    roomDetailModel(rId: string) {

    }

}