<template>
  <div style="margin-top: 20px">
    <div v-for="log in logs" :key="log.msg">
      {{ log.time }} <br> {{ log.msg }}
    </div>
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop, Watch } from 'vue-property-decorator'
import { Set } from '@/@types/set'
import { fetchItem } from '@/api/job'
import { AppModule } from '@/store/modules/app'

// export interface Log {
//   code: number
//   msg: string
//   time: number
// }

// export interface Srvmodel {
//   logs: Log[]
// }

// export interface SitejobClass {
//   srvmodels: Srvmodel[]
//   status: string
//   updateunits: boolean
//   vaultid: string
// }

// export interface Sitejob {
//   sitejob: SitejobClass
// }

@Component({
  name: 'SetDeploymentModalContent'
})

export default class extends Vue {
  @Prop() readonly set: Set

  lastJob: any | null = null

  get lastJobGuid() {
    return this.set?.deployment_config?.lastjobguid || null
  }

  get lastJobGuidMessage() {
    if (!this.lastJobGuid) {
      return 'Отсутствует информация о рабочих заданиях на создание приёмника, связанных с данным set-ом.'
    }
  }

  @Watch('lastJobGuid', { immediate: true })
  async handleLog(val: string) {
    if (val) {
      const { result } = await fetchItem(val)
      console.log(result, 'result')
      this.lastJob = result
    }
  }

  get logs() {
    const jobLogs = this.lastJob.sitejob.srvmodels[0].logs
    return jobLogs
    // if (jobLogs) {
    //   const res = Object
    //     .entries(jobLogs)
    //     .map(([time, msg]) => ({ time: this.parseTimestamp(parseInt(time)), msg }))

    //   return res
    // }
  }

  get language() {
    return AppModule.language
  }

  parseTimestamp(date: number) {
    return new Date(date).toLocaleDateString(this.language, {
      hour: '2-digit',
      minute: 'numeric',
      second: 'numeric',
      day: 'numeric',
      month: 'long',
      hourCycle: 'h23'
    })
  }
}

</script>

"result": {
        "adminLogs": null,
        "completed": true,
        "dataSync": null,
        "finishedAt": "2024-08-30T07:54:43.742074Z",
        "groupjob": {
            "jobs": null,
            "name": ""
        },
        "guid": "eee42bb7-6dd5-497c-b7e6-0856895d7b7f",
        "log": {},
        "name": "tgtunit_deploy",
        "pipeline": null,
        "progress": 100,
        "result": "Job finished. Completed 2 model(s) out of 2. There were 2 warning(s).",
        "sitejob": {
            "archiveunits": false,
            "createunits": true,
            "dryrun": false,
            "function": "tgtunit_deploy",
            "netmodels": null,
            "pattern": "",
            "payload": null,
            "placementid": 40,
            "projectid": 1,
            "setid": 7,
            "sitecfgid": 23,
            "srvinventory": null,
            "srvmodels": [
                {
                    "compile": false,
                    "compileinputs": {
                        "attributeidx": 0,
                        "idx": 0,
                        "mode": 0,
                        "scope": ""
                    },
                    "cpu": 2,
                    "customargs": {
                        "accountid": 7,
                        "rgid": 6
                    },
                    "defaultgateway": "192.168.204.1",
                    "disks": [
                        {
                            "boot": true,
                            "compileinputs": {
                                "attributeidx": 0,
                                "idx": 0,
                                "mode": 0,
                                "scope": "storage"
                            },
                            "customargs": {
                                "gridid": 2002,
                                "pool": "vmstor",
                                "sepid": 1
                            },
                            "destroy": false,
                            "jmid": "DMSJ0TVP",
                            "name": "vda",
                            "size": 23622320128,
                            "srcname": "vda",
                            "targetid": "41437",
                            "targetstorageid": "1:vmstor",
                            "utility": false,
                            "uuid": ""
                        }
                    ],
                    "dns": [
                        "192.168.204.1"
                    ],
                    "emid": "",
                    "flavor": "",
                    "hostname": "AVD-ub2004-src-DHumJNC",
                    "iscomplete": true,
                    "iserror": false,
                    "isvalid": true,
                    "jmid": "SJ0TVP",
                    "logs": [
                        {
                            "code": 1,
                            "msg": "NIC 'NMSJ0TVQ' uses explicit Network type \u0026 ID specification",
                            "time": 1725004361
                        },
                        {
                            "code": 0,
                            "msg": "model validated OK",
                            "time": 1725004361
                        },
                        {
                            "code": 0,
                            "msg": "Compute instance ID 30900 created",
                            "time": 1725004461
                        },
                        {
                            "code": 0,
                            "msg": "Compute started",
                            "time": 1725004480
                        },
                        {
                            "code": 0,
                            "msg": "Refreshed compute facts",
                            "time": 1725004483
                        },
                        {
                            "code": 0,
                            "msg": "New server record created",
                            "time": 1725004483
                        },
                        {
                            "code": 0,
                            "msg": "agent for new unit created",
                            "time": 1725004483
                        },
                        {
                            "code": 0,
                            "msg": "new unit created",
                            "time": 1725004483
                        },
                        {
                            "code": 0,
                            "msg": "server record updated with new unit ID",
                            "time": 1725004483
                        },
                        {
                            "code": 0,
                            "msg": "Set ID 7 updated with unit ID 10 as target",
                            "time": 1725004483
                        }
                    ],
                    "modelunitid": 3,
                    "name": "tst-30-01",
                    "nics": [
                        {
                            "compileinputs": {
                                "attributeidx": 0,
                                "idx": 0,
                                "mode": 0,
                                "scope": "network"
                            },
                            "customargs": {
                                "netid": 10,
                                "nettype": "EXTNET"
                            },
                            "defaultgw": "",
                            "destroy": false,
                            "ipaddr": [
                                "45.134.255.42/24"
                            ],
                            "jmid": "NMSJ0TVQ",
                            "linkstate": 0,
                            "mac": "",
                            "name": "ce-30900-10",
                            "preferred": true,
                            "srcip": [
                                "192.168.205.234/22"
                            ],
                            "srcmac": "52:54:00:2f:58:55",
                            "srcname": "enp1s0",
                            "targetid": "ce-30900-10",
                            "targetnetworkid": "EXTNET:10",
                            "uninetid": 0,
                            "utility": false
                        }
                    ],
                    "os": {
                        "release": "Ubuntu 20.04.5 LTS",
                        "targetid": "762",
                        "type": "linux"
                    },
                    "pwrstate": "ON",
                    "ram": 957,
                    "seqno": 0,
                    "status": "DEPLOYED",
                    "targetid": "30900",
                    "unisrvidin": 0,
                    "unisrvidout": 13,
                    "unitidin": 0,
                    "unitidout": 10,
                    "unituri": "",
                    "utility": false
                }
            ],
            "status": "",
            "updateunits": false,
            "vaultid": "00000000-0000-0000-0000-000000000000"
        },
        "stage": 1,
        "startDate": "2024-08-30T07:52:37.850528Z",
        "startedAt": "2024-08-30T07:52:39.729716Z",
        "status": "OK",
        "timeout": 130,
        "timestamp": 0,
        "type": "sitejob",
        "updatedAt": "2024-08-30T07:54:43.742074Z"
    },

 Error in render: "TypeError: Cannot read properties of null (reading 'sitejob')"
как вывести logs?