/*
 * Copyright 2026 Oleg Borodin <onborodin@gmail.com>
 */
package filecli

import (
	"context"
	"fmt"
	"net/http"
)

func (cli *Client) DeleteFile(ctx context.Context, rawpath string) (bool, error) {
	var err error
	var exist bool

	ref, err := ParsePath(rawpath)
	if err != nil {
		return exist, err
	}
	uri := ref.FileEP()
	req, err := http.NewRequestWithContext(ctx, http.MethodDelete, uri, nil)
	if err != nil {
		return exist, err
	}
	req.Header.Set("User-Agent", cli.userAgent)
	req.Header.Set("Accept", "*/*")
	resp, err := cli.httpClient.Do(req)
	if err != nil {
		return exist, err
	}
	defer resp.Body.Close()
	if resp.StatusCode == http.StatusNotFound {
		return exist, err
	}
	if resp.StatusCode != http.StatusOK {
		err := fmt.Errorf("Unxected response code %s", resp.Status)
		return exist, err
	}
	exist = true
	return exist, err
}
