<?php

namespace app\Http\Controllers\Api\Web;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Models\IbuHamil;
use App\Http\Models\Provinsi;
use App\Http\Models\Kabupaten;
use App\Http\Models\Kecamatan;
use App\Http\Models\Desa;
use File,Sentinel,Validator;

class APIWEBIbuHamilController extends Controller
{
    public function addBumil(Request $request)
    {
        // $data = $request->all();

        $bumil = new IbuHamil;
        $bumil->nik = $request->data['nik'];
        $bumil->nama_bumil = $request->data['nama_bumil'];
        $bumil->tmp_lahir = $request->data['tmp_lahir'];
        $bumil->tgl_lahir = date('Y-m-d', strtotime($request->data['tgl_lahir']));
        $bumil->agama = $request->data['agama'];
        $bumil->pendidikan = $request->data['pendidikan'];
        $bumil->pekerjaan = $request->data['pekerjaan'];
        if (!empty($request->data['nama_suami'])) {
            $bumil->nama_suami = $request->data['nama_suami'];
        }
        $bumil->alamat_ktp = $request->data['alamat_ktp'];
        $bumil->provinsi_ktp_id = $request->data['provinsi_ktp_id'];
        $bumil->kabupaten_ktp_id = $request->data['kabupaten_ktp_id'];
        $bumil->kecamatan_ktp_id = $request->data['kecamatan_ktp_id'];
        $bumil->desa_ktp_id = $request->data['desa_ktp_id'];
        $bumil->no_tlp = $request->data['no_tlp'];
        $bumil->foto = $request->secret['namaGambar'];
        $bumil->save();

        if ($bumil) {
            return ['status'=>'success','code'=>'200','message'=>'Data Ibu Hamil Berhasil Dibuat !!','data'=>$bumil ]; 
        }else{
            return ['status'=>'success','code'=>'200','message'=>'Data Ibu Hamil Gagal Dibuat !!' ]; 
        }
    }

    public function editBumil(Request $request)
    {
        $bumil = IbuHamil::find($request->data['id_bumil']);
        $bumil->nik = $request->data['nik'];
        $bumil->nama_bumil = $request->data['nama_bumil'];
        $bumil->tmp_lahir = $request->data['tmp_lahir'];
        $bumil->tgl_lahir = date('Y-m-d', strtotime($request->data['tgl_lahir']));
        $bumil->agama = $request->data['agama'];
        $bumil->pendidikan = $request->data['pendidikan'];
        $bumil->pekerjaan = $request->data['pekerjaan'];
        if (!empty($request->data['nama_suami'])) {
            $bumil->nama_suami = $request->data['nama_suami'];
        }
        $bumil->alamat_ktp = $request->data['alamat_ktp'];
        $bumil->provinsi_ktp_id = $request->data['provinsi_ktp_id'];
        $bumil->kabupaten_ktp_id = $request->data['kabupaten_ktp_id'];
        $bumil->kecamatan_ktp_id = $request->data['kecamatan_ktp_id'];
        $bumil->desa_ktp_id = $request->data['desa_ktp_id'];
        $bumil->no_tlp = $request->data['no_tlp'];
        $bumil->foto = $request->secret['namaGambar'];
        $bumil->save();

        if ($bumil) {
            return ['status'=>'success','code'=>'200','message'=>'Data Ibu Hamil Berhasil Diperbaharui !!','data'=>$bumil ]; 
        }else{
            return ['status'=>'success','code'=>'200','message'=>'Data Ibu Hamil Gagal Diperbaharui !!' ]; 
        }
    }
}
