using System;
using System.Collections;
using System.Collections.Generic;
using Agora.Rtc.LitJson;
using UnityEngine;
using UnityEngine.UI;

public class UpLoadmageItem : MonoBehaviour
{
    public string path;
    public void init(Texture2D texture2D,string str)
    {
        this.transform.GetComponent<RawImage>().texture = texture2D;


        string filePath = str;
        string uuid =  Guid.NewGuid().ToString();
        string fileName = uuid+".png";
        string objecName = "workorder/"+int.Parse(ChuLiItemManager.ChooseData["id"].ToString())+"/";
        // 文件预上传
        JsonData jData = new JsonData();
        byte[] data = texture2D.EncodeToPNG();
        jData["size"] = data.Length;
        jData["ext"] = "jpg";
        jData["name"] = fileName;

        JsonData fileData = new JsonData();
        fileData["filePath"] = filePath;
        fileData["fileSize"] = data.Length;
        fileData["fileName"] = fileName;
        // project /{ projectId}/ inspection /{ projectInspectionId}/{ taskId}
        fileData["objectName"] = objecName;

        JsonData fildData = fileData;
        // 文件上传
        DownLoadXRManager.PutFile(fildData["filePath"].ToString(), fildData["fileName"].ToString(), fildData["objectName"].ToString() + fildData["fileName"].ToString(),uuid, int.Parse(fildData["fileSize"].ToString()), msg =>
        {
            Debug.Log(" 文件上传成功 " + msg);
            this.path = objecName+fileName;
        });
    }

    public void delete()
    {
        BaoGaoUpLoadManager.Instance.itemlist.Remove(this);
        Destroy(this.transform.GetComponent<RawImage>().texture);
        Destroy(this.gameObject);
    }
}